home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000015_icon-group-sender _Tue Jan 16 09:28:24 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  1KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 16 Jan 1996 12:30:17 MST
  2. Date: Tue, 16 Jan 1996 09:28:24 -0700
  3. From: swampler@noao.edu
  4. Subject: Re: Initialising tables
  5. To: H.Lawson@tees.ac.uk
  6. Cc: icon-group@cs.arizona.edu
  7. Message-Id: <swampler-9600161628.AA00097538@orpheus.gemini.edu>
  8. In-Reply-To: <4B78DE79AC@scm_arkengarthdale.tees.ac.uk>
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10. Status: O
  11.  
  12.  
  13.  
  14. Hamish Lawson wrote:
  15. > Is there an quick way to initialise tables, along the lines of the
  16. > list assignment below?
  17. >    aList := ["this","list","is","a","list"]
  18. > I've cooked up the following, but is there a more concise way?
  19. >    aTable := table()
  20. >    every entry := ![["bob",2],["sue",5],["fred",12],["mary",9]] do
  21. >       aTable[entry[1]] := entry[2]
  22.  
  23. Well, this isn't any more concise in the short term, but it might be
  24. better in the long run to use a procedure to do the initialization:
  25.  
  26. aTable := mktable(["bob",2],["sue",5],["fred",12],["mary",9])
  27.  
  28. where mktable() is:
  29.  
  30. procedure mktable(L[])
  31.    local aT, pair
  32.  
  33.    aT := table()
  34.    every pair := !L do {
  35.       aT[pair[1]] := pair[2]
  36.       }
  37.    return aT
  38. end
  39.  
  40. -- 
  41. Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under AURA)]
  42. The Gods that smiled upon your birth are laughing now. -- fortune cookie
  43.